package com.fc.advbox.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.fc.advbox.common.ResponseJson;
import com.fc.advbox.controller.admin.BaseController;
import com.fc.advbox.entity.AdvOrgMonthProfitEntity;
import com.fc.advbox.service.IOrgMonthProfitService;
import com.fc.advbox.utils.Constant;
import com.fc.advbox.utils.RRException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Created by E7450 on 2018/7/14.
 */
@RestController
@RequestMapping("/api/org/profit/monthly")
@Api(value="用户月收益接口", tags={"用户月收益接口"})
public class OrgMonthProfitController extends BaseController {
    @Autowired
    private IOrgMonthProfitService orgMonthProfitService;

    @ApiOperation(value = "POST -- 查询用户所在org的月收益记录",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>必填参数: userId: 用户ID</i></li>" +
//                    "<li><i>可选参数: orgName: 组织名称</i></li>" +
                    "<li><i>默认参数：page: 1, 当前页，默认值1</i></li>" +
                    "<li><i>默认参数：limit: 每次查询个数，默认为10</i></li>" +
                    "</ul>")
    @PostMapping("/list")
    @RequiresPermissions("api:org:profit:view")
    public ResponseJson doQueryList(@RequestBody Map<String, Object> params) {
        //校对并赋值 offset和limit
        calculatePagination(params);

        if(!params.containsKey("userId") || params.get("userId") == null)
        {
            throw new RRException("userId不能为空!");
        }

        Map<String, Object> resp = orgMonthProfitService.queryListByOrgType(params);
        return ResponseJson.success(resp);
    }

    @ApiOperation(value = "POST -- 查询某orgId的月收益记录",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>选填参数: orgId: orgID</i></li>" +
                    "<li><i>默认参数：page: 1, 当前页，默认值1</i></li>" +
                    "<li><i>默认参数：limit: 每次查询个数，默认为10</i></li>" +
                    "</ul>")
    @PostMapping("/org/list")
    @RequiresPermissions("api:org:profit:view")
    public ResponseJson doQueryMonthList(@RequestBody JSONObject params) {
        //校对并赋值 offset和limit
        calculatePagination(params);

        List<AdvOrgMonthProfitEntity> resp = orgMonthProfitService.queryList(params);
        return ResponseJson.success(resp);
    }
}
